import HelloWorld from '@/pages/demo/HelloWorld'
import HelloWorld2 from '@/pages/demo/HelloWorld2'
import Counter from '@/pages/demo/Counter'
import Layout from '@/layout/Layout'

const meta = { requiresAuth: true }

const appRoute = [
  {
    name: 'home',
    path: '/',
    // redirect: { name: 'index' },
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'index',
        meta,
        component: () => import('@/pages/index')
      }
    ]
  }
]

const otherRoute = [
  // 页面重定向使用 必须保留
  {
    path: '/redirect/:path*',
    component: {
      beforeCreate () {
        const path = this.$route.params.path
        this.$router.replace(JSON.parse(path))
      },
      render: function (h) {
        return h()
      }
    }
  },
  // 登录
  {
    path: '/login',
    name: 'login',
    component: () => import('@/pages/login')
  }
]

/**
 * 错误页面
 */
const errorPage = [
  // 404
  {
    path: '*',
    name: 'error-page-404',
    component: () => import('@/pages/error-page-404')
  }
]

export default [
  {
    path: '/helloworld',
    component: HelloWorld,
    beforeEnter: (to, from, next) => {
      // ...
      console.log('component beforeEnter', to, from, next)
      next()
    }
  },
  {
    path: '/hello/:id',
    component: HelloWorld2
  },
  {
    path: '/demo/counter',
    component: Counter
  },
  ...appRoute,
  ...otherRoute,
  ...errorPage
]
